package com.wb.mianxiangduixiang.bms;

/**
 * @author 黄衡熙
 * @version 1.0
 * @date 2025年07月22日14:34
 */
public class LoanSavingAccount extends SavingAccount implements Loanable{

    // 贷款金额
    private double loanAmount;

    public double getLoanAmount() {
        return loanAmount;
    }

    public void setLoanAmount(double loanAmount) {
        this.loanAmount = loanAmount;
    }
//贷款
    @Override
    public void providerLoan(double money) {
        setLoanAmount(getLoanAmount()+money);
        setBalance(super.getBalance()+money);
        System.out.println("成功贷款："+money+"当前账户余额为:"+getBalance());
        setLoanAmount(getLoanAmount()+money);

        // 由于此处进行了简化,没有审批流程,默认直接贷款成功
        // 因此,贷款后贷款金额发生变化即可
    }

    @Override
    public boolean payLoan(double money) {
        // 由于此处属于贷款的储蓄账户
        // 因此,还贷时要求当前账户余额不低于还贷的金额
        if(money > getLoanAmount()){
            System.out.println("还款金额大于贷款金额，请查询贷款金额，再重新输入还款金额");
        }else {
            if (getBalance() < money) {
                System.out.println("还款失败，余额不足已支付还款金额，当前余额为:" + getBalance());
            } else {
                setBalance(getBalance() - money);
                setLoanAmount(getLoanAmount() - money);
                System.out.println("还款成功，当前余额为:" + getBalance());
            }
        }
        return false;
    }

    @Override
    public double queryLoan() {
        System.out.println("当前贷款金额为:"+getLoanAmount());
        // 查询当前贷款的金额
        return getLoanAmount();
    }

}